package com.work.lxykeeper.utils;


import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;

import com.work.lxykeeper.adapter.CommonAdapter;


/**
 * 取代ListView的LinearLayout，使之能够成功嵌套在ScrollView中
 * 
 * @author WZ 2016/1/31
 */
public class LinearLayoutForListView extends LinearLayout {
	private CommonAdapter adapter;
	private OnClickListener onClickListener = null;

	/**
	 * 绑定布局
	 */
	public void bindLinearLayout() {
		int count = adapter.getCount();
		this.removeAllViews();
		for (int i = 0; i < count; i++) {
			View v = adapter.getView(i, null, null);
			v.setOnClickListener(this.onClickListener);
			addView(v, i);
		}
	}

	public LinearLayoutForListView(Context context) {
		super(context);
	}

    /**
     * 提供加解密后 byte[]-->String 以及 String-->byte[]的转换工具类
     * Created by LGC on 2017/5/7.
     */

    public static class HexUtils {
        private final static String HEX = "0123456789ABCDEF";
        /**
         * 二进制转(16进制)字符串
         */
        private static String ByteToHex(byte[] bytesKey) {
            if (bytesKey == null)
                return "";
            StringBuilder sb = new StringBuilder();
            for (byte b : bytesKey) {
                sb.append(HEX.charAt((b >> 4) & 0x0f)).append(HEX.charAt(b & 0x0f));
            }
            return sb.toString();
        }

        /**
         * (16进制)字符转二进制
         */
        private static byte[] HexToByte(String hexString) {
            int len = hexString.length() / 2;
            byte[] result = new byte[len];
            for (int i = 0; i < len; i++)
                result[i] = Integer.valueOf(hexString.substring(2 * i, 2 * i + 2), 16).byteValue();
            return result;
        }
    }
}